package com.jasonzhou.onetomanycontrol.room

import com.jasonzhou.onetomanycontrol.room.entity.DeviceRecord
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext

class DeviceRecordRepository(private val deviceRecordDao: DeviceRecordDao) {
    suspend fun findRecordByAddress(address: String): DeviceRecord? {
        return withContext(Dispatchers.IO) {
            deviceRecordDao.findRecordByAddress(address)
        }
    }

    suspend fun getAllRecord(): List<DeviceRecord> {
        return withContext(Dispatchers.IO) {
            deviceRecordDao.getAllRecord()
        }
    }

    suspend fun delColor(id: Long) {
        return withContext(Dispatchers.IO) {
            deviceRecordDao.delColor(id)
        }
    }

    suspend fun insertAll(vararg device: DeviceRecord): List<Long> {
        return withContext(Dispatchers.IO) {
            deviceRecordDao.insertAll(*device)
        }
    }

    suspend fun updateColor(vararg device: DeviceRecord) {
        return withContext(Dispatchers.IO) {
            deviceRecordDao.updateColor(*device)
        }
    }

}